package com.algoruthm6;

import java.util.Arrays;

public class InsertionSort {

    public static void sort(int[] array){
        for(int i=1;i<array.length;i++){
            int temp = array[i];
            int j = i;
            while((--j>=0)&&array[j]>temp){
                array[j+1] = array[j];
            }
            array[j+1] = temp;
            System.out.println("i="+i+"-->"+ Arrays.toString(array));
        }
    }

    public static void main(String[] args){
        int[] array = new int[]{4,3,6,8,9,7,10,5,1,2};
        System.out.println("array:"+ Arrays.toString(array));
        sort(array);
        System.out.println("sorted array:"+ Arrays.toString(array));
    }
}
